package com.egreen.asset.controller;


import com.egreen.asset.service.IPointAccountService;
import com.egreen.common.Result;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author cloudJiang
 * @since 2022-07-16
 */
@RestController
@RequestMapping("/pointAccount")
public class PointAccountController {
    @Autowired
    IPointAccountService pointAccountService;

    /**
     * 创建积分账户，不需要参数传递，返回去的值为账户的id
     * 无需传参故用get请求
     * <p>
     * 1@param
     */
    @ApiOperation(value = "创建积分账户", notes = "为用户创建一个积分账户")
    @GetMapping("/addPointAccount")
    public Result addPointAccount() {
        Long aLong = pointAccountService.addPointAccount();
        return Result.OK(aLong);
    }

    @ApiOperation(value = "获取积分账户余额")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", required = true)
    })
    @GetMapping("/getUserPoint")
    public Result getUserPoint(@RequestParam("id") Long id) {
        return Result.OK(pointAccountService.selectPointByAccountId(id));
    }
}

